package cn.ht.jywrwater.module.ht.controller.admin.dashboard.waterquality;

import cn.ht.jywrwater.framework.common.pojo.CommonResult;
import cn.ht.jywrwater.module.ht.controller.admin.dashboard.waterquality.vo.*;
import cn.ht.jywrwater.module.ht.controller.admin.statisticsdevicecount.vo.StatisticsDeviceCountRespVO;
import cn.ht.jywrwater.module.ht.convert.statisticsdevicecount.StatisticsDeviceCountConvert;
import cn.ht.jywrwater.module.ht.dal.dataobject.statisticsdevicecount.StatisticsDeviceCountDO;
import cn.ht.jywrwater.module.ht.dal.mysql.statisticsdevicecount.StatisticsDeviceCountMapper;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.RandomUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.ht.jywrwater.framework.common.pojo.CommonResult.success;

@Tag(name = "大屏 - 水质大屏")
@RestController
@RequestMapping("/ht/water-quality-dashboard")
@Validated
public class WaterQualityDashboardController {

    @Resource
    private StatisticsDeviceCountMapper statisticsDeviceCountMapper;

    @GetMapping("/statistics-device-count-list")
    @Operation(summary = "水质大屏获得设备在线统计列表")
    public CommonResult<List<StatisticsDeviceCountRespVO>> getStatisticsDeviceCountList() {
        List<StatisticsDeviceCountDO> list = statisticsDeviceCountMapper.selectList();
        return success(StatisticsDeviceCountConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/source-water-quality")
    @Operation(summary = "水质大屏水源水质")
    public CommonResult<List<SourceWaterQualityVo>> getSourceWaterQuality() {

        List<SourceWaterQualityVo> result = CollUtil.newArrayList();
        for (int i = 0; i < 4; i++) {
            SourceWaterQualityVo sourceWaterQualityVo = new SourceWaterQualityVo();
            sourceWaterQualityVo.setSourceWaterType(i + 1);
            sourceWaterQualityVo.setCount(i + 1);
            sourceWaterQualityVo.setWaterRatio(i + 1);
            result.add(sourceWaterQualityVo);
        }
        return success(result);
    }

    @GetMapping("/water-lv-quality")
    @Operation(summary = "水质大屏余氯数据")
    public CommonResult<WaterLvQualityVo> getWaterLvQuality() {
        WaterLvQualityVo result = new WaterLvQualityVo();
        result.setProducedWaterLvQualityCount(CollUtil.newArrayList(3, 4, 5, 6));
        result.setTabWaberLvQualityCount(CollUtil.newArrayList(3, 4, 5, 6));

        List<WaterStationLvQualityVo> lvo = CollUtil.newArrayList();
        for (int i = 1; i < 10; i++) {
            WaterStationLvQualityVo vo = new WaterStationLvQualityVo();
            vo.setQualify(i);
            vo.setNotQualify(i);
            vo.setVeryNotQualify(i);
            vo.setLvException(i);
            lvo.add(vo);
        }
        result.setProcudedWaterStationLvQualityList(lvo);
        result.setTagBaterStationLvQualityList(lvo);
        return CommonResult.success(result);
    }

    @GetMapping("/water-ph-quality")
    @Operation(summary = "水质大屏PH数据")
    public CommonResult<WaterLvQualityVo> getWaterPhQuality() {
        WaterLvQualityVo result = new WaterLvQualityVo();
        result.setProducedWaterLvQualityCount(CollUtil.newArrayList(3, 4, 5, 6));
        result.setTabWaberLvQualityCount(CollUtil.newArrayList(3, 4, 5, 6));

        List<WaterStationLvQualityVo> lvo = CollUtil.newArrayList();
        for (int i = 1; i < 10; i++) {
            WaterStationLvQualityVo vo = new WaterStationLvQualityVo();
            vo.setQualify(i);
            vo.setNotQualify(i);
            vo.setVeryNotQualify(i);
            vo.setLvException(i);
            lvo.add(vo);
        }
        result.setProcudedWaterStationLvQualityList(lvo);
        result.setTagBaterStationLvQualityList(lvo);
        return CommonResult.success(result);
    }

    @GetMapping("/water-comparative")
    @Operation(summary = "水质大屏出厂与末梢对比分析")
    public CommonResult<List<WaterComparativeVO>> getWaterComparativeData(@Valid @RequestBody WaterComparativeReqVO reqVO) {
        List<WaterComparativeVO> result = CollUtil.newArrayList();
        for (int i = 0; i < 8; i++) {
            WaterComparativeVO waterComparativeVO = new WaterComparativeVO();
            waterComparativeVO.setDataTime(LocalDateTimeUtil.now().minusHours(i * 2));
            waterComparativeVO.setTabWaterData(RandomUtil.randomFloat(10));
            waterComparativeVO.setProducedWaterData(RandomUtil.randomFloat(10));
            result.add(waterComparativeVO);
        }
        return CommonResult.success(result);
    }


    @GetMapping("/water-quality-realtime")
    @Operation(summary = "水质大屏最新水质检测")
    public CommonResult<WaterComparativeVO> getWaterRealtimeData(@Valid @RequestBody WaterComparativeReqVO reqVO) {

        return CommonResult.success(null);
    }


}
